package com.magic.smartcity.view.more.hospital

import android.opengl.Visibility
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.Navigation
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.android.material.snackbar.Snackbar
import com.magic.smartcity.R
import com.magic.smartcity.databinding.FragmentHospitalPatientCardBinding
import com.magic.smartcity.view.more.adapters.HospitalPatientCardAdapter
import com.magic.smartcity.view.more.viewmodels.HospitalViewModel

class HospitalPatientCardFragment : Fragment() {

    private lateinit var binding: FragmentHospitalPatientCardBinding
    private val model by lazy {
        ViewModelProvider(this).get(HospitalViewModel::class.java)
    }
    private val cardAdapter = HospitalPatientCardAdapter()

    override fun onResume() {
        super.onResume()
        //获取就诊人卡片
        model.getPatientCardList()
    }

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        binding = FragmentHospitalPatientCardBinding.inflate(layoutInflater)

        initView()

        return binding.root
    }

    private fun initView() {

        //初始化就诊人卡片信息
        binding.patientCardRy.adapter = cardAdapter
        binding.patientCardRy.layoutManager =
            LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
        model.hospitalPatientCardList.observe(viewLifecycleOwner) {
            if (it.isEmpty()) {
                binding.textView26.visibility = View.GONE
            } else {
                binding.textView26.visibility = View.VISIBLE
            }
            cardAdapter.setData(it)
        }

        binding.addPatientCard.setOnClickListener {
            Navigation.findNavController(it)
                .navigate(R.id.action_hospitalPatientCardFragment_to_hospitalPatientCardAddFragment)
        }


    }


}